<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
</head>
<body style="padding: 64px">
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-block">
            <input type="number" name="mobile" lay-verify="mobile" autocomplete="off" placeholder="请输入手机号码"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="password" name="password" lay-verify="password" autocomplete="off" placeholder="请输入密码"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">验证码</label>
        <div class="layui-input-block">
            <input type="text" name="captcha" lay-verify="required" autocomplete="off" placeholder="请输入验证码"
                   class="layui-input">
            <img src="{:captcha_src()}" alt="captcha" style="position: absolute;top:3px;right: 3px"
                 onclick="this.src='{:captcha_src()}?' + Math.random();"/>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="login">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script src="/static/layui/layui.js"></script>
<script>
    layui.use(['layer', 'form'], function () {
        let form = layui.form;
        //自定义验证规则
        form.verify({
            mobile: [
                /^[1][3,4,5,7,8,9][0-9]{9}$/,
                '手机号码格式不正确',
            ],
            password: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ]
        });
        form.on('submit(login)', function (data) {
            layui.jquery.ajax({
                url: '/index/index/login/',
                method: 'POST',
                data: data.field,
                success: function (value) {
                    if (value.code == 2) {
                        layui.layer.msg(value.msg);
                        return false;
                    }
                    location.reload();//重新加载当前页面
                }
            });
            return false;
        });
    });
</script>
</body>
</html>
